package org.caenv.interpreter.pojo.instructions;

import java.util.Map;
import org.caenv.interpreter.ExecutionException;

public class Mov implements Instruction {

    public static final String ATTR_DEST = "dest";
    public static final String ATTR_SRC = "src";
    
    public String src;
    public String dest;
    
    @Override
    public boolean build(Map<String, String> attributes) {
        if (attributes == null || !attributes.containsKey(ATTR_DEST) || !attributes.containsKey(ATTR_SRC)) {
            return false;
        } else {
            this.src = attributes.get(ATTR_SRC);
            this.dest = attributes.get(ATTR_DEST);
            return true;
        }
    }

    @Override
    public boolean execute(ExecutionPlan executionPlan) throws ExecutionException {
        try{
            executionPlan.getMemoryManager().setValue(dest, executionPlan.getMemoryManager().getValue(src));
            return true;
        }catch (ExecutionException e){
            return false;
        }
    }
}
